package com.byq.mm.smartlib.cluster.activity.client;




import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ImageButton;

import com.byq.mm.smartlib.R;
import com.byq.mm.abstractx.cluster.client.event.ClusterChangeEvent;
import com.byq.mm.application.cluster.client.OnoffClient;
import com.byq.mm.smartlib.tools.IconManager;

public class ClientOnoffActivity extends ClientClusterActivity {
	ImageButton onoff;

	Button refresh;

	@Override
	public void onCreate(Bundle savedInstanceState) {
		
		super.onCreate(savedInstanceState);
		
		  setContentView(R.layout.switchconponent);
		
		  
		

		onoff = (ImageButton)this.findViewById(R.id.componentSwitch);
		String dct = this.client.getDevice().getType();
		Drawable dw = IconManager.getGrayIconDrawable(this, dct);
		onoff.setImageDrawable(dw);
		
		onoff.setOnClickListener(new View.OnClickListener() {
			public void onClick(View v) {
				OnoffClient co = (OnoffClient)client;
				co.toggle();
			}

		});

		refresh = (Button)this.findViewById(R.id.refreshGet);
		refresh.setOnClickListener(new View.OnClickListener() {
			public void onClick(View v) {
				OnoffClient co = (OnoffClient)client;
				co.refresh();
			}
		});
		OnoffClient co = (OnoffClient)client;
		co.refresh();
		  setImage();
	}
	void setImage(){
		OnoffClient co = (OnoffClient)client;
		String dct = this.client.getDevice().getType();
		Drawable dw;
		
		if(!co.isOn()){
			dw = IconManager.getGrayIconDrawable(this, "off");
			
			
		}
		
		else{
			dw = IconManager.getIconDrawable(this, "on");
			
		}
		onoff.setImageDrawable(dw);
	}

	@Override
	protected void onStart() {
		super.onStart();
	
	}
	@Override
	protected void onStop() {
		super.onStop();
	}
	@Override
	protected void update(ClusterChangeEvent e) {
		setImage();
		
	}
	

}